package com.zj.osm.entity.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zj.osm.entity.greendao.PowerSupplySchemeDetails;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "POWER_SUPPLY_SCHEME_DETAILS".
*/
public class PowerSupplySchemeDetailsDao extends AbstractDao<PowerSupplySchemeDetails, Long> {

    public static final String TABLENAME = "POWER_SUPPLY_SCHEME_DETAILS";

    /**
     * Properties of entity PowerSupplySchemeDetails.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property SourceCode = new Property(1, String.class, "sourceCode", false, "SOURCE_CODE");
        public final static Property SourceType = new Property(2, String.class, "sourceType", false, "SOURCE_TYPE");
        public final static Property VoltageLevel = new Property(3, String.class, "voltageLevel", false, "VOLTAGE_LEVEL");
        public final static Property LineNumber = new Property(4, String.class, "lineNumber", false, "LINE_NUMBER");
        public final static Property RunMethod = new Property(5, String.class, "runMethod", false, "RUN_METHOD");
        public final static Property PowerSupplyCapacity = new Property(6, String.class, "powerSupplyCapacity", false, "POWER_SUPPLY_CAPACITY");
        public final static Property ImportLineMethod = new Property(7, String.class, "importLineMethod", false, "IMPORT_LINE_METHOD");
        public final static Property PowerSupplySchemeId = new Property(8, Long.class, "powerSupplySchemeId", false, "POWER_SUPPLY_SCHEME_ID");
    }

    private Query<PowerSupplySchemeDetails> powerSupplyScheme_PowerSupplySchemeDetailsListQuery;

    public PowerSupplySchemeDetailsDao(DaoConfig config) {
        super(config);
    }
    
    public PowerSupplySchemeDetailsDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"POWER_SUPPLY_SCHEME_DETAILS\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"SOURCE_CODE\" TEXT," + // 1: sourceCode
                "\"SOURCE_TYPE\" TEXT," + // 2: sourceType
                "\"VOLTAGE_LEVEL\" TEXT," + // 3: voltageLevel
                "\"LINE_NUMBER\" TEXT," + // 4: lineNumber
                "\"RUN_METHOD\" TEXT," + // 5: runMethod
                "\"POWER_SUPPLY_CAPACITY\" TEXT," + // 6: powerSupplyCapacity
                "\"IMPORT_LINE_METHOD\" TEXT," + // 7: importLineMethod
                "\"POWER_SUPPLY_SCHEME_ID\" INTEGER);"); // 8: powerSupplySchemeId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"POWER_SUPPLY_SCHEME_DETAILS\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, PowerSupplySchemeDetails entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String sourceCode = entity.getSourceCode();
        if (sourceCode != null) {
            stmt.bindString(2, sourceCode);
        }
 
        String sourceType = entity.getSourceType();
        if (sourceType != null) {
            stmt.bindString(3, sourceType);
        }
 
        String voltageLevel = entity.getVoltageLevel();
        if (voltageLevel != null) {
            stmt.bindString(4, voltageLevel);
        }
 
        String lineNumber = entity.getLineNumber();
        if (lineNumber != null) {
            stmt.bindString(5, lineNumber);
        }
 
        String runMethod = entity.getRunMethod();
        if (runMethod != null) {
            stmt.bindString(6, runMethod);
        }
 
        String powerSupplyCapacity = entity.getPowerSupplyCapacity();
        if (powerSupplyCapacity != null) {
            stmt.bindString(7, powerSupplyCapacity);
        }
 
        String importLineMethod = entity.getImportLineMethod();
        if (importLineMethod != null) {
            stmt.bindString(8, importLineMethod);
        }
 
        Long powerSupplySchemeId = entity.getPowerSupplySchemeId();
        if (powerSupplySchemeId != null) {
            stmt.bindLong(9, powerSupplySchemeId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PowerSupplySchemeDetails entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String sourceCode = entity.getSourceCode();
        if (sourceCode != null) {
            stmt.bindString(2, sourceCode);
        }
 
        String sourceType = entity.getSourceType();
        if (sourceType != null) {
            stmt.bindString(3, sourceType);
        }
 
        String voltageLevel = entity.getVoltageLevel();
        if (voltageLevel != null) {
            stmt.bindString(4, voltageLevel);
        }
 
        String lineNumber = entity.getLineNumber();
        if (lineNumber != null) {
            stmt.bindString(5, lineNumber);
        }
 
        String runMethod = entity.getRunMethod();
        if (runMethod != null) {
            stmt.bindString(6, runMethod);
        }
 
        String powerSupplyCapacity = entity.getPowerSupplyCapacity();
        if (powerSupplyCapacity != null) {
            stmt.bindString(7, powerSupplyCapacity);
        }
 
        String importLineMethod = entity.getImportLineMethod();
        if (importLineMethod != null) {
            stmt.bindString(8, importLineMethod);
        }
 
        Long powerSupplySchemeId = entity.getPowerSupplySchemeId();
        if (powerSupplySchemeId != null) {
            stmt.bindLong(9, powerSupplySchemeId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public PowerSupplySchemeDetails readEntity(Cursor cursor, int offset) {
        PowerSupplySchemeDetails entity = new PowerSupplySchemeDetails( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // sourceCode
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // sourceType
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // voltageLevel
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // lineNumber
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // runMethod
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // powerSupplyCapacity
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // importLineMethod
            cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8) // powerSupplySchemeId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PowerSupplySchemeDetails entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setSourceCode(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setSourceType(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setVoltageLevel(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setLineNumber(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setRunMethod(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setPowerSupplyCapacity(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setImportLineMethod(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setPowerSupplySchemeId(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PowerSupplySchemeDetails entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PowerSupplySchemeDetails entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(PowerSupplySchemeDetails entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "powerSupplySchemeDetailsList" to-many relationship of PowerSupplyScheme. */
    public List<PowerSupplySchemeDetails> _queryPowerSupplyScheme_PowerSupplySchemeDetailsList(Long powerSupplySchemeId) {
        synchronized (this) {
            if (powerSupplyScheme_PowerSupplySchemeDetailsListQuery == null) {
                QueryBuilder<PowerSupplySchemeDetails> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.PowerSupplySchemeId.eq(null));
                powerSupplyScheme_PowerSupplySchemeDetailsListQuery = queryBuilder.build();
            }
        }
        Query<PowerSupplySchemeDetails> query = powerSupplyScheme_PowerSupplySchemeDetailsListQuery.forCurrentThread();
        query.setParameter(0, powerSupplySchemeId);
        return query.list();
    }

}
